package com.zhangwei.xutils.utils;

import android.content.Context;

import com.lidroid.xutils.DbUtils;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.zhangwei.xutils.utils
 * @Description:
 * @date 15/10/17 下午6:57
 */

public class XutilsHelper {
    private static XutilsHelper helper = new XutilsHelper();
    private DbUtils dbUtils;
    private static Context context;
    private DbUtils.DaoConfig config;


    public static void init(Context context) {
        XutilsHelper.context = context;
    }


    private XutilsHelper() {
    }

    public static XutilsHelper getInstance() {
        return helper;
    }


    public DbUtils.DaoConfig getDaoConfig() {
        if (config == null) {
            config = new DbUtils.DaoConfig(context);
            config.setDbDir(FileUtils.getDbFile(context).getAbsolutePath());
            config.setDbName(AppConfig.DB_NAME);
            config.setDbVersion(1);
            config.setDbUpgradeListener(new DbUtils.DbUpgradeListener() {
                @Override
                public void onUpgrade(DbUtils db, int oldVersion, int newVersion) {

                }
            });
        }

        return config;
    }

    public DbUtils getDbUtils() {
        if (dbUtils == null) {
            dbUtils = DbUtils.create(getDaoConfig());
        }
        return dbUtils;
    }
}
